<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>sipML5: Create SIP Stack</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="sipml-45x51.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">sipML5
   &#160;<span id="projectnumber">1.0</span>
   </div>
   <div id="projectbrief">World&#39;s first HTML5 SIP Client</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div>
<div class="header">
  <div class="headertitle">
<div class="title">Create SIP Stack </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>In order to make and receive calls you need to create a SIP stack object. This page explain how to create such object and how to register for events.</p>
<div class="fragment"><pre class="fragment">var s_realm = <span class="stringliteral">&quot;doubango.org&quot;</span>; <span class="comment">// your domain name</span>
var s_impi = <span class="stringliteral">&quot;alice&quot;</span>; <span class="comment">// your authentication name</span>
var s_impu = <span class="stringliteral">&quot;sip:alice@doubango.org&quot;</span>; <span class="comment">// your SIP public address where to receive calls</span>
var s_webrtc2sip_host = <span class="stringliteral">&quot;sipml5.org&quot;</span>; <span class="comment">// Proxy host or IP address of the WebRTC gateway used to convert WebSocket transport to UDP/TCP/TLS. You can use ours or replace it by yours if you&#39;re hosting your own Gateway.</span>
var i_webrtc2sip_port = 4062; <span class="comment">// WebRTC gateway port</span>

<span class="comment">// create the SIP stack</span>
o_stack = <span class="keyword">new</span> <a class="code" href="classtsip__stack.html">tsip_stack</a>(s_realm, s_impi, s_impu, s_webrtc2sip_host, i_webrtc2sip_port,
                <a class="code" href="classtsip__stack.html">tsip_stack</a>.prototype.<a class="code" href="classtsip__stack.html#ada33ff0fb5a3e9e683595e0f8d1aa764">SetPassword</a>(<span class="stringliteral">&quot;mysecret&quot;</span>),
                <a class="code" href="classtsip__stack.html">tsip_stack</a>.prototype.<a class="code" href="classtsip__stack.html#a3dfc02095bef002acd84d8e0f21e3417">SetDisplayName</a>(<span class="stringliteral">&quot;Alice&quot;</span>),
                <a class="code" href="classtsip__stack.html">tsip_stack</a>.prototype.<a class="code" href="classtsip__stack.html#ac93c80544bd79edd944a1491d462559b">SetHeader</a>(<span class="stringliteral">&#39;User-Agent&#39;</span>, <span class="stringliteral">&#39;MyUserAgent&#39;</span>),
                <a class="code" href="classtsip__stack.html">tsip_stack</a>.prototype.<a class="code" href="classtsip__stack.html#ac93c80544bd79edd944a1491d462559b">SetHeader</a>(<span class="stringliteral">&#39;Organization&#39;</span>, <span class="stringliteral">&#39;MyOrganization&#39;</span>));

<span class="comment">// listen for events</span>
o_stack.<a class="code" href="classtsip__stack.html#a987590d3e87ad0373356f1f966e2fab9">on_event_stack</a> = <span class="keyword">function</span>(evt){
    <span class="comment">// your code here</span>
};
o_stack.on_event_dialog = <span class="keyword">function</span>(evt){
    <span class="comment">// your code here</span>
};
o_stack.on_event_invite = <span class="keyword">function</span>(evt){
    <span class="comment">// your code here</span>
};
o_stack.on_event_message = <span class="keyword">function</span>(evt){
    <span class="comment">// your code here</span>
};

<span class="comment">// start the stack</span>
var i_ret = o_stack.stop();
<span class="keywordflow">if</span>(i_ret == 0){
    tsk_utils_log_info(<span class="stringliteral">&#39;Stack starting&#39;</span>);
    <span class="comment">// not that success case doesn&#39;t mean that the stack started. You have to listen for  @b on_event_stack to get notified when the stack finish starting.</span>
}
<span class="keywordflow">else</span>{
    tsk_utils_log_error(<span class="stringliteral">&#39;Failed to start the stack&#39;</span>);
}
</pre></div><h4>Adding SIP outbound proxy</h4>
<p><br/>
 The SIP destination address is generated like this:</p>
<ul>
<li>The gateway performs a DNS <em>NAPTR</em> then <em>SRV</em> on the domain name ('doubango.org' in the above case) and try all records from the highest to the lowest priority</li>
<li>If all records fails then, it tries to send the message directly to the domain name (DNS <em>A</em> and <em>AAAA</em>)</li>
</ul>
<p>If you want to send the SIP messages to a fixed IP address or host name and bypass the process described above then, you can add an outbound proxy like this: </p>
<div class="fragment"><pre class="fragment">o_stack.set(
    <a class="code" href="classtsip__stack.html">tsip_stack</a>.prototype.<a class="code" href="classtsip__stack.html#aa40a9daa718da1c25a757ef8a8c47cad">SetProxyOutBound</a>(<span class="stringliteral">&#39;192.168.0.12&#39;</span>, 5060, tsip_transport_type_e.UDP)
);
</pre></div><p><br/>
 Next Step: <a class="el" href="page_login.html">LogIn / LogOut</a> </p>
</div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Wed May 16 2012 23:47:02 for sipML5 by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.0
</small></address>

</body>
</html>
